package com.xhs.common.error;

public class XhsErrorException extends Exception {
  private static final long serialVersionUID = -6357149550353160810L;

  private final XhsError error;

  private static final int DEFAULT_ERROR_CODE = -99;

  public XhsErrorException(String message) {
    this(XhsError.builder().code(DEFAULT_ERROR_CODE).msg(message).build());
  }

  public XhsErrorException(XhsError error) {
    super(error.toString());
    this.error = error;
  }

  public XhsErrorException(XhsError error, Throwable cause) {
    super(error.toString(), cause);
    this.error = error;
  }

  public XhsErrorException(Throwable cause) {
    super(cause.getMessage(), cause);
    this.error = XhsError.builder().code(DEFAULT_ERROR_CODE).msg(cause.getMessage()).build();
  }

  public XhsError getError() {
    return this.error;
  }
}
